package cn.edu.scau.cmi.guihao.pane;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.guihao.domin.singleMultipleModel.Chairman;
import cn.edu.scau.cmi.guihao.domin.singleMultipleModel.Marshal;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;

public class SingleMultiplePane extends Pane implements Initializable {
	
	@FXML
	private Button createChairmanBtn;
	
	@FXML
	private TextArea chairmanArea;
	
	@FXML
	private TextField marshalName;
	
	@FXML
	private TextArea marshalArea;
	
	public SingleMultiplePane() {
		FXMLLoader loader = new FXMLLoader(getClass().getResource("/cn/edu/scau/cmi/guihao/view/SingleMultipleModelView.fxml"));
        loader.setRoot(this);
        loader.setController(this);
        try {
            loader.load();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
	
	public void createChairman() {
		if(Chairman.getInstance()==null) {
			Chairman chairman = Chairman.getInstanceChairman();			
			String string = chairmanArea.getText();
			chairmanArea.setText(string+"\n创建对象成功"+"\n"+chairman.getName());
		}else {
			Chairman chairman = Chairman.getInstanceChairman();	
			String string = chairmanArea.getText();
			chairmanArea.setText(string+"\n对象已存在，返回已存在对象");
		}
	}
	
	public void createMarshal() {
		String name = marshalName.getText();
		String string = marshalArea.getText();
		if(name.equals("")) {
			marshalArea.setText(string+"\n请输入姓名");
		}else {
			List<Marshal> marshals = Marshal.addInstances(name);
			if(marshals.size()>10) {
				marshalArea.setText(string+"\n人数已满不能再创建对象");
			}else {
				string=string+"\n对象创建成功"+"\n人员名单:";
				for (int i = 0; i < marshals.size(); i++) {
					string = string+"\n"+marshals.get(i).getName();
				}
				marshalArea.setText(string);
			}			
		}
	}

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		
	}
	
	
}
